/**
 * @ClassName LC3101
 * @Author ykx
 * @Date 2024/7/6 9:11
 * @Version 1.0
 */
public class LC3101 {
    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 1, 1};
        System.out.println(new LC3101().countAlternatingSubarrays(nums));
    }

    public long countAlternatingSubarrays(int[] nums) {
        int len = 1;
        long res = 1;
        for (int i = 1; i < nums.length; i++) {
            len = 1 + (nums[i] != nums[i - 1] ? len : 0);
            res += len;
        }
        return res;
    }


}
